<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Model\memberModal;
use App\Admin\Repositories\FourDepartment;
use App\Models\Department;
use App\Models\FourCampus;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class FourDepartmentController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(\App\Models\FourDepartment::with('campus'), function (Grid $grid) {
            $grid->column('id')->bold()->sortable();
            $grid->column('name')->tree(true,false);//开启树状表格功能
            $grid->column('campus.campus_name','院区');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('name');
            });
            $grid->quickSearch(['id', 'name']);
            //导出
            $grid->export()->xlsx()->filename('科室信息');
            //导入
            $grid->tools(function (Grid\tools $tools){
                $tools->append(new \App\Admin\Actions\Modal\memberModal());
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FourDepartment(), function (Show $show) {
            $show->field('id');
            $show->field('pid');
            $show->field('name');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(\App\Models\FourDepartment::with('campus'), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->select('campus_id','所属院区')->options(FourCampus::pluck('campus_name','id'));
            $form->select('pid','上级科室')->options(['1'=>'内科','2'=>'外科']);
            $form->switch('status','科室状态');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
